package org.dydl.common.config;

import java.util.HashMap;
import java.util.Map;

import org.dydl.model.system.SysUser;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

public class CustomUserService implements UserDetailsService {

	// @Autowired
	// private ISysUserService userService;

	// 默认
	public static Map<String, SysUser> sysUserList = new HashMap<>();

	@Override
	public UserDetails loadUserByUsername(String username) {
		// 初始化
		// "a66abb5684c45962d887564f08346e8d"
		sysUserList.put("admin", new SysUser(1L, "admin", "0192023a7bbd73250516f069df18b500", "", true, 0));
		if (sysUserList.containsKey(username)) {
			return new User(sysUserList.get(username).getUserName(), sysUserList.get(username).getPassword(), true,
					true, true, true, AuthorityUtils.createAuthorityList(new String[] { "ADMIN" }));
		}
		return null;
		// if (userService == null) {
		//
		// return null;
		// }
		/********************************************/

		// Search search = new Search();
		// search.addFilterEqual("userName", username);
		// @SuppressWarnings("unchecked")
		// List<SysUser> user = (List<SysUser>) userService.search(search).getData();

		// List<com.yorma.common.po.SysRole> rols =
		// userService.get(user.getId()).getRoles();

		// if (user.size() > 0) {
		//
		// String[] roles = user.get(0).getAuthorities();
		//
		// // UserContext和权限列表集成，返回UserContext对象
		// return new User(user.get(0).getUserName(), user.get(0).getPassword(), true,
		// true, true, true,
		// AuthorityUtils.createAuthorityList(roles));
		//
		// } else {
		//
		// return null;
		//
		// }

	}

}